#pragma once

#include "InetAddress.h"
#include <string>

int create_nonblocking();

class Socket
{
private:
    int m_fd;
    std::string m_ip;
    uint16_t m_port;

public:
    Socket(int fd);
    ~Socket();

    int fd();
    std::string ip();
    uint16_t port();

    void set_ip_port(const char* ip,uint16_t port);
    void set_reuseaddr(bool on);
    void set_reuseport(bool on);
    void set_tcpnodelay(bool on);
    void set_keepalive(bool on);
    void bind(const InetAddress &servaddr);
    void listen(int listennum = 128);
    int accept(InetAddress &clientaddr);
};